/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package encaps.utils;

import java.util.Iterator;
import java.util.Map;


public class StringUtil {

    private StringUtil() {

    }

    public static boolean isEmpty(String s) {
        if(s == null) return true;
        return s.trim().isEmpty();
    }

    public static String constructSelectQuery(String table, String primaryKeyColumn, Map criteria) {
        StringBuilder sb = new StringBuilder();
        sb.append("SELECT ");
        sb.append(primaryKeyColumn);
        sb.append(" FROM ");
        sb.append(table);
        sb.append(" WHERE ");
        Iterator keyIterator = criteria.keySet().iterator();
        Object key = keyIterator.next();
        sb.append(key);
        sb.append(" LIKE '%");
        sb.append(criteria.get(key));
        sb.append("%'");

        while(keyIterator.hasNext()) {
            sb.append(" AND ");
            key = keyIterator.next();
            sb.append(key.toString());
            sb.append(" LIKE '%");
            sb.append(criteria.get(key));
            sb.append("%'");
        }
        return sb.toString();
    }
}
